<?php

namespace Admin\Controller;

class GuideController extends AdminbaseController {

    function _initialize() {
        parent::_initialize();
        $this->currentModel = D("Guide");
    }

    //首页
    public function index() {

        $requestMap = $this->convertRequestToMap();

        //分页
        $count = $this->currentModel->getListCount($requestMap);
        $page = $this->page($count, C("DEFAULT_PAGE_SIZE"));

        //获取分类列表
        $list = $this->currentModel->queryForList($page, $requestMap);

        $this->assign('list', $list);
        $this->assign("page", $page->show('Admin', $this->parameter));
        $this->display();

    }

    /**
     * 添加数据
     */
    public function addPost() {

        $guideData["name"] = $_REQUEST["name"];
        $guideData["target_url"] = $_REQUEST["targetUrl"];
        $guideData["create_time"] = getCurrentDate();
        $guideData["icon_path"] = $_REQUEST["iconPath"];

        $this->currentModel->add($guideData);

        $this->success("添加成功", U("guide/index"));

    }

    /**
     * 更新数据
     */
    public function editPost() {

        $id = $_REQUEST["guideId"];

        $guide = $this->currentModel->queryById($id);

        $guide["name"] = $_REQUEST["name"];
        $guide["icon_path"] = $_REQUEST["iconPath"];
        $guide["target_url"] = $_REQUEST["targetUrl"];

        $this->currentModel->updateInfo($guide);

        $this->success("更新成功", U("guide/index"));

    }

}